package com.nny.Demo250;

import java.util.*;

import static java.util.Collections.emptyMap;

public class Demo2 {
    public  static void menu(){
        System.out.println("欢迎来到员工管理系统");
        System.out.println("0.退出系统");
        System.out.println("1.添加员工");
        System.out.println("2.查询所有员工");
        System.out.println("3.根据员工姓名查询");
        System.out.println("4.删除员工");
        System.out.println("5.根据员工编号查询");
        System.out.println("6.根据员工编号修改年龄");
        System.out.println("请选择你需要进行的操作系统");
    }

    public static void main(String[] args) {
        TestMap testMap = new TestMap();
        Map<String, Emp> empMap = new HashMap<>();
        boolean flag = true;
        Scanner scanner = new Scanner(System.in);

        while (flag) {
            menu();
            int n = scanner.nextInt();
            switch (n) {
                case 0:
                    flag = false;
                    break;
                case 1:
                    System.out.println("请输入员工信息");
                    System.out.println("1.请输入员工编号");
                    String emNumber = scanner.next();
                    System.out.println("2.请输入员工姓名");
                    String emName = scanner.next();
                    System.out.println("请输入员工年龄");
                    int emAge = scanner.nextInt();
                    Emp addemp = new Emp(emNumber, emName, emAge);
                    testMap.addEmp(empMap, addemp);
                    System.out.println("员工添加成功!");
                    break;

                case 2:
                    System.out.println("所有员工信息:");
                    testMap.findAllEmp(empMap);
                    break;

                case 3:
                    System.out.println("请输入你需要查询的姓名");
                    com.nny.Demo250.Emp findemp = testMap.findEmpByName(empMap, scanner.next());
                    if (findemp != null) {
                        System.out.println("查询结果: " + findemp);
                    } else {
                        System.out.println("未找到该员工");
                    }
                    break;

                case 4:
                    System.out.println("请输入你需要删除的员工编号");
                    String number = scanner.next();
                    testMap.deleteEmpByNumber(empMap, number);
                    System.out.println("员工删除成功!");
                    break;

                case 5:
                    System.out.println("请输入你需要查询的员工编号");
                    String findNumber = scanner.next();
                    com.nny.Demo250.Emp findEmp = testMap.findEmpByNumber(empMap, findNumber);
                    if (findEmp != null) {
                        System.out.println("查询结果: " + findEmp);
                    } else {
                        System.out.println("未找到该员工");
                    }
                    break;

                case 6:
                    System.out.println("请输入你需要修改的员工编号");
                    String updateNumber = scanner.next();
                    System.out.println("请输入你需要修改的员工年龄");
                    int updateAge = scanner.nextInt();
                    testMap.updateEmpAge(empMap, updateNumber, updateAge);
                    System.out.println("员工年龄更新成功!");
                    break;

                default:
                    System.out.println("无效选择，请重新输入");
            }
        }
        scanner.close();
        System.out.println("感谢使用员工管理系统，再见!");
    }
    }

